<?php
// TODO REVIEW Trung Nguyen 2009-07-21
// Missing Class Header
/**
 * Object Relational Persistence Mapping Class for table: emer_reception
 *
 * @package	com.athena
 * @author	LHV
 */
class EmerReception extends ORDataObject {

	/**#@+
	 * Fields of table: emer_reception mapped to class members
	 */
    var $emer_reception_id     = '';
	var $patient_id            = '';
	var $aid_giver_name        = '';
	var $aid_giver_address     = '';
	var $aid_giver_phone       = '';
	var $check_in_time         = '';
	var $check_in_reason       = '';
	var $injury_description    = '';
	var $enum_injury_level     = '';
	var $from_place            = '';
	var $enum_transport        = '';
	var $pre_diagnosis		   = '';
	var $receptionist_id       = '';
	/**#@-*/

    const ENUM_INJ_LEVEL_DEAD   =   4;
	/**
	 * DB Table
	 */
	var $_table = 'emer_reception';

	/**
	 * Primary Key
	 */
	var $_key = 'emer_reception_id';

	/**
	 * Internal Name
	 */
	var $_internalName = 'EmerReception';

	/**
	 * Handle instantiation
	 */
	public function EmerReception() {
		parent::ORDataObject();
	}
    /**
     * Set data to the object
     *
     * @param int $patientId
     * @param string $aiderName
     * @param string $aiderAddress
     * @param string $aiderPhone
     * @param string $checkInTime
     * @param string $checkInReason
     * @param string $injuryDes
     * @param int $level
     * @param string $fromPlace
     * @param int $transport
     * @param string $preDiag
     * @param int $receptionist
     */
	public function setData($patientId, $aiderName, $aiderPhone, $aiderAddress, $checkInTime,
	       $checkInReason, $injuryDes, $level, $fromPlace, $transport, $preDiag, $receptionist){
		$data =   array(
		  'patient_id'        =>  $patientId,
          'aid_giver_name'    =>  $aiderName,
          'aid_giver_address' =>  $aiderAddress,
          'aid_giver_phone'   =>  $aiderPhone,
          'check_in_time'     =>  $checkInTime,
          'check_in_reason'   =>  $checkInReason,
          'injury_description'=>  $injuryDes,
          'enum_injury_level' =>  $level,
          'from_place'        =>  $fromPlace,
          'enum_transport'    =>  $transport,
          'pre_diagnosis'     =>  $preDiag,
          'receptionist_id'   =>  $receptionist
		);
		$this->populateArray($data);
	}

	/**#@+
     * Getters
     */
	public function getPatientId(){
		return $this->patient_id;
	}

	public function getAiderName(){
        return $this->aid_giver_name;
    }

    public function getAiderPhone(){
        return $this->aid_giver_phone;
    }

    public function getAiderAddress(){
        return $this->aid_giver_address;
    }

    public function getCheckInDate(){
    	return $this->getLocalizedDate('check_in_time');
    }

    public function getCheckInTime(){
    	$time  =   $this->getLocalizedDate('check_in_time', 'short', 'time');
        $parts =   explode(':', $time);
        return $parts[0] . ":" . $parts[1];
    }

    public function getInjuryLevel(){
    	return $this->enum_injury_level;
    }

    public function getTransport(){
        return $this->enum_transport;
    }

    public function getCheckInReason(){
    	return $this->check_in_reason;
    }

    public function getInjuryDescription(){
    	return $this->injury_description;
    }

    public function getOriginalPlace(){
    	return $this->from_place;
    }

    public function getOriginalDiagnosis(){
        return $this->pre_diagnosis;
    }
    /**#@-*/

    /**
     * Get latest reception info object of given patient
     *
     * @param int $patientId input patientId
     * @return object EmerReception object
     */
	public function getLatestObjectByPatientId($patientId){
        $sql    =   "SELECT $this->_key FROM $this->_table WHERE patient_id=$patientId AND check_in_time = (SELECT MAX(check_in_time) FROM $this->_table WHERE patient_id=$patientId)";
        $res    =   $this->_execute($sql);
        $obj    =   Celini::newORDO('EmerReception', $res->fields[$this->_key]);
        return $obj;
	}


}
?>
